package com.apes.fn.tms.model;

import com.apes.framework.jpa.BaseModel;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.plugin.soe.annotations.State;
import com.apes.framework.plugin.soe.annotations.States;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;

/**
 * 派车单明细
 * @author yiny
 * 2020.3.13
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = CarDetails.CONST_TABLE_NAME,uniqueConstraints = {@UniqueConstraint(columnNames = {"car_infomation_id","waybill_id"})})
public class CarDetails extends BaseModel {
    public static final String CONST_TABLE_NAME = "TMS_CAR_DETAILS";

    @Id
    @Column(name = "id")
    @ApesGenerator(code = CONST_TABLE_NAME, name = "派车单明细")
    @Comment("派车单明细")
    private String id;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "car_infomation_id", referencedColumnName = "id")
    @Comment("派车单号")
    private CarInformation carInformationId;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "waybill_id", referencedColumnName = "id")
    @Comment("运单号")
    private Waybill waybillId;

    @Column(name = "execution_number")
    @Comment("运单执行顺序号")
    private int executionNumber;

//    @States(name="运输状态",
//            values = {@State(id="collection", name="待揽收"), @State(id = "sendCar", name = "待派车"),
//                    @State(id="loading", name = "待装车"), @State(id="inTransit", name="运输中"), @State(id="received", name="已签收")})
//    @Column(name = "status")
//    @Comment("状态")
//    private String status; // 未装货，已装货，已签收
}
